/**
 * jims
 */
package com.jims.master.modules.drug.service;

import java.util.List;

import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.drug.entity.DrugExportDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.drug.entity.DrugDetails;
import com.jims.master.modules.drug.dao.DrugDetailsDao;

/**
 * 药理信息Service
 * @author DT
 * @version 2017-03-15
 */
@Service
@Transactional(readOnly = true)
public class DrugDetailsService extends CrudService<DrugDetailsDao, DrugDetails> {
	@Autowired
	private DrugDetailsDao drugDetailsDao;

	public DrugDetails get(String id) {
		return super.get(id);
	}
	
	public List<DrugDetails> findList(DrugDetails drugDetails) {
		return super.findList(drugDetails);
	}
	
	public Page<DrugDetails> findPage(Page<DrugDetails> page, DrugDetails drugDetails) {
		return super.findPage(page, drugDetails);
	}
	
	@Transactional(readOnly = false)
	public int save(DrugDetails drugDetails) {
		int i=0;
		if(StringUtils.isNotBlank(drugDetails.getId())){
			drugDetails.preUpdate();
			i=dao.update(drugDetails);
		}
		else if(StringUtils.isNotBlank(drugDetails.getDrugInfoId())){
			DrugDetails drugDetails1=drugDetailsDao.findBydrugInfoId(drugDetails);
			if (drugDetails1!=null){
				drugDetails.preUpdate();
				i=dao.update(drugDetails);
		}
			else {
				drugDetails.preInsert();
				drugDetails.updateOrgId();
				i=dao.insert(drugDetails);
			}
	}
		return i;
	}
	
	@Transactional(readOnly = false)
	public int delete(DrugDetails drugDetails) {
		return super.delete(drugDetails);
	}

	public DrugDetails findBydrugInfoId(DrugDetails drugDetails){
		return drugDetailsDao.findBydrugInfoId(drugDetails);
	}
}